//
//  DrillMessageVC.m
//  DefendHealth
//
//  Created by UNOHACHA on 17/2/21.
//  Copyright © 2017年 iMacOne. All rights reserved.
//

#import "DrillMessageVC.h"
#import "DriMessCell.h"
#import "CustomPickerView.h"
#import "PlanDetailVC.h"
@interface DrillMessageVC ()<UITableViewDelegate,UITableViewDataSource,UIMyPickerDataSource,UIMyPickerDelegate>
{
    NSArray * arr;
    NSArray * arr1;
    UIView *bkview1;
    CustomPickerView * pickerView;
}

@property (nonatomic,strong) UITableView *runMessTab;


@end

@implementation DrillMessageVC


- (UITableView *)runMessTab
{
    if (!_runMessTab) {
        _runMessTab = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
        _runMessTab.showsVerticalScrollIndicator = NO;
        _runMessTab.delegate = self;
        _runMessTab.dataSource = self;
        _runMessTab.backgroundColor = k_TableBackColor;
        _runMessTab.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _runMessTab;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.Nav.backgroundColor = kClearColor;
    
    arr=@[@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",];
    arr1=@[@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30"];
    
    [self.view addSubview:self.runMessTab];
    [self.view bringSubviewToFront:self.Nav];

    [self addView2];
}




- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return section == 0 ? 2:4;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    tableView.tableHeaderView = [self sharedFirstView];
    
     return section == 0 ? [UIView new] :[self planMessage ];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return section == 0 ? 10.f:50.f;
    
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return section == 0 ? nil :[self footBtn ];
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
     return section == 0 ? 0.f :k_TabBarHeight;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return indexPath.section == 0 ? 54:54;
}





- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString * cellIdentif = [DriMessCell cellReuseID:indexPath.section with:indexPath.row];
    UITableViewCell *cell = nil;
    
     cell = [tableView dequeueReusableCellWithIdentifier:cellIdentif];
    if (!cell) {
        cell = [[NSClassFromString(cellIdentif) alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentif];
    }
    
    return cell;
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 1 ) {
            pickerView =[[CustomPickerView alloc]initWithFrame:CGRectMake(0, kScreenHeight-180, kScreenWidth, 180)];
            pickerView.dataSource=self;
            pickerView.delegate=self;
            //    pickerView.ScrolleViewArray
            [self.view addSubview:pickerView];
        }
    }else{
        PlanDetailVC * planvc= [[PlanDetailVC alloc]init];
        planvc.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:planvc animated:YES];
    }
}


-(void)cancel{
    [self cancel];
}

-(void)save{
    [self save];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIButton *)footBtn {
    
    UIButton * btn = [UIButton creatBtnWithFrame:CGRectMake(0, 0, kScreenWidth, k_TabBarHeight) btnTitle:@"使用计划 GO !" btnTitleColor:kWhiteColor btnTitleFont:16 btnTagPrice:0 btnSetImage:nil btnBackgroundColor:kBlackColor isCorner:NO action:^(UIButton *button) {
        [self xianshi];
        
    }];
    return btn;
}


- (UIView *)planMessage {
    
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 55)];
    view.backgroundColor = kWhiteColor;
    
    UIView * wightView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 5)];
    wightView.backgroundColor = k_TableBackColor;
    [view addSubview:wightView];
    
    UILabel * firsL = [ReduceCode creatLabelWithFrame:CGRectMake(20, kMaxY(wightView.frame)+12, kScreenWidth-24, 20) title:@"计划详情" titleColor:UIColorFromRGB(0x333333) font:14 textAlignment:NSTextAlignmentLeft];
    [view addSubview:firsL];
    
//    UILabel * detailL = [ReduceCode creatLabelWithFrame:CGRectMake(12, kMaxY(firsL.frame)+12, kScreenWidth-24, 20) title:@"微胖界小伙伴首选,提高心肺功能 有效身体塑性" titleColor:UIColorFromRGB(0x666666) font:12 textAlignment:NSTextAlignmentLeft];
//    detailL.numberOfLines = 0;
//    [view addSubview:detailL];

    return view;
}










- (UIView *)sharedFirstView {
    
    [self.leftbutton setImage:IMAGE(@"left") forState:UIControlStateNormal];
    [self.rigltbutton setImage:IMAGE(@"share") forState:UIControlStateNormal];
    
    UIView * firsBigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 355)];
    firsBigView.backgroundColor = kWhiteColor;
    UIImageView * bigImg = [ReduceCode creatImageVeiwWithFrame:CGRectMake(0, 0, kScreenWidth, 220) imageName:@"组-1" isCorner:NO];
    bigImg.backgroundColor = UIColorFromRGB(0xcccaca);
    [firsBigView addSubview:bigImg];
    
    
    UILabel * titL = [ReduceCode creatLabelWithFrame:CGRectMake(30, 90, kScreenWidth-20, 30) title:@"7天5公里快步走" titleColor:kWhiteColor font:24 textAlignment:NSTextAlignmentLeft];
    //titL.centerY = bigImg.centerY;
    [bigImg addSubview:titL];
    
    UILabel * dayL = [ReduceCode creatLabelWithFrame:CGRectMake(0, kMaxY(titL.frame)+30, kScreenWidth/3, 20) title:@"20" titleColor:kWhiteColor font:16 textAlignment:NSTextAlignmentCenter];
    [bigImg addSubview:dayL];
    
    
    UILabel * consumptionL = [ReduceCode creatLabelWithFrame:CGRectMake(kScreenWidth/3, dayL.y, kScreenWidth/3, 20) title:@"1200" titleColor:kWhiteColor font:16 textAlignment:NSTextAlignmentCenter];
    [bigImg addSubview:consumptionL];
    
    UILabel * difficultyL = [ReduceCode creatLabelWithFrame:CGRectMake(kScreenWidth/3*2, dayL.y, kScreenWidth/3, 20) title:@"10" titleColor:kWhiteColor font:16 textAlignment:NSTextAlignmentCenter];
    [bigImg addSubview:difficultyL];
    
    
    NSArray * STR = @[@"运动/天数",@"消耗/千卡",@"平均/分钟"];
    for (int D = 0; D<3; D++) {
        UILabel * dayL = [ReduceCode creatLabelWithFrame:CGRectMake(kScreenWidth/3*D, kMaxY(difficultyL.frame)+5, kScreenWidth/3, 12) title:STR[D] titleColor:UIColorFromRGB(0x888888) font:12 textAlignment:NSTextAlignmentCenter];
        [bigImg addSubview:dayL];
    }
    
    UILabel *jieshaoL = [ReduceCode creatLabelWithFrame:CGRectMake(20, kMaxY(bigImg.frame)+10, kScreenWidth-40, 65) title:@"碎片训练，微胖界小伙伴首选，提高心肺功能 有效身体塑性 由易到难 坚持20天" titleColor:UIColorFromRGB(0x333333) font:14 textAlignment:NSTextAlignmentLeft];
    jieshaoL.numberOfLines = 0;
    jieshaoL.lineBreakMode = UILineBreakModeCharacterWrap;
    [firsBigView addSubview:jieshaoL];
    
    [ToolUtil createLine:kMaxY(jieshaoL.frame)+1 superView:firsBigView lift:20 width:kScreenWidth-40 hight:1 color:K_LineColor];
    
    UILabel *lab1 = [ReduceCode creatLabelWithFrame:CGRectMake(20, kMaxY(jieshaoL.frame)+10, 40, 45) title:@"适用人群" titleColor:UIColorFromRGB(0xe85f2b) font:18 textAlignment:NSTextAlignmentLeft];
    lab1.numberOfLines = 0;
    lab1.lineBreakMode = UILineBreakModeCharacterWrap;
    [firsBigView addSubview:lab1];
    
    UIImageView *img1 = [ReduceCode creatImageVeiwWithFrame:CGRectMake(kMaxX(lab1.frame), kMaxY(jieshaoL.frame)+19, 5, 5) imageName:@"circle" isCorner:YES];
    [firsBigView addSubview:img1];
    
    UILabel *lab2 = [ReduceCode creatLabelWithFrame:CGRectMake(kMaxX(lab1.frame)+5, kMaxY(jieshaoL.frame)+12, 100, 20) title:@" 所有微胖人士" titleColor:UIColorFromRGB(0x333333) font:14 textAlignment:NSTextAlignmentLeft];
    
    [firsBigView addSubview:lab2];
    
    UIImageView *img2 = [ReduceCode creatImageVeiwWithFrame:CGRectMake(kMaxX(lab1.frame), kMaxY(lab2.frame)+10, 5, 5) imageName:@"circle" isCorner:YES];
    [firsBigView addSubview:img2];
    
    UILabel *lab3 = [ReduceCode creatLabelWithFrame:CGRectMake(kMaxX(lab1.frame)+5, kMaxY(lab2.frame)+2, 120, 20) title:@" 心肺功能较弱人士" titleColor:UIColorFromRGB(0x333333) font:14 textAlignment:NSTextAlignmentLeft];
    
    [firsBigView addSubview:lab3];
    
    UILabel *lab4 = [ReduceCode creatLabelWithFrame:CGRectMake(kMaxX(lab3.frame)+5, kMaxY(jieshaoL.frame)+10, 40, 45) title:@"禁忌人群" titleColor:UIColorFromRGB(0xe85f2b) font:18 textAlignment:NSTextAlignmentLeft];
    lab4.numberOfLines = 0;
    lab4.lineBreakMode = UILineBreakModeCharacterWrap;
    [firsBigView addSubview:lab4];
    
    UIImageView *img3 = [ReduceCode creatImageVeiwWithFrame:CGRectMake(kMaxX(lab4.frame), kMaxY(jieshaoL.frame)+19, 5, 5) imageName:@"circle" isCorner:YES];
    [firsBigView addSubview:img3];
    
    UILabel *lab5 = [ReduceCode creatLabelWithFrame:CGRectMake(kMaxX(lab4.frame)+5, kMaxY(jieshaoL.frame)+12, 100, 20) title:@" 65岁以上" titleColor:UIColorFromRGB(0x333333) font:14 textAlignment:NSTextAlignmentLeft];
    [firsBigView addSubview:lab5];
    
    UIImageView *img4 = [ReduceCode creatImageVeiwWithFrame:CGRectMake(kMaxX(lab4.frame), kMaxY(lab5.frame)+10, 5, 5) imageName:@"circle" isCorner:YES];
    [firsBigView addSubview:img4];
    
    UILabel *lab6 = [ReduceCode creatLabelWithFrame:CGRectMake(kMaxX(lab4.frame)+5, kMaxY(lab5.frame)+2, 120, 20) title:@" 骨伤未愈人群" titleColor:UIColorFromRGB(0x333333) font:14 textAlignment:NSTextAlignmentLeft];
    
    [firsBigView addSubview:lab6];
    
//    UIView * wightView =[[UIView alloc]initWithFrame:CGRectMake(0, kMaxY(bigImg.frame), kScreenWidth, 50)];
//    wightView.backgroundColor = kWhiteColor;
//    [firsBigView addSubview:wightView];
//
//    UILabel * peoL = [ReduceCode creatLabelWithFrame:CGRectMake(12, (wightView.height-20)/2, wightView.width/3, 20) title:@"有260人 正在执行" titleColor:UIColorFromRGB(0x333333) font:14 textAlignment:NSTextAlignmentLeft];
//    [wightView addSubview:peoL];
//
//    for (NSInteger P = 0; P<6; P++) {
//        UIImageView * bigImg = [ReduceCode creatImageVeiwWithFrame:CGRectMake(kMaxX(peoL.frame)+12+30*P, peoL.y, 25, 25) imageName:@"" isCorner:YES];
//        bigImg.centerY = peoL.centerY;
//        bigImg.backgroundColor = kBlueColor;//UIColorFromRGB(0xffffff);
//        if (P == 5) {
//            bigImg.image = IMAGE(@"point");
//            bigImg.backgroundColor = kWhiteColor;
//            bigImg.width = 7; bigImg.height =  11; bigImg.centerY = peoL.centerY;bigImg.x = kScreenWidth-17;
//            bigImg.layer.masksToBounds = NO;
//        }
//        
//        [wightView addSubview:bigImg];
//    }
    
    return firsBigView;
}
- (NSInteger)numberOfComponentsInMyPickerView:(nonnull MyPickerView *)myPickerView{
    return 2;
}
- (NSInteger)myPickerView:(nonnull MyPickerView *)myPickerView numberOfRowInComponent:(NSInteger)component{
    if (component == 0) {
        return 10;
    }else{
        return 30;
    }
    return 10;
}
- (nullable NSString *)myPickerView:(nonnull MyPickerView *)myPickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (component == 0) {
        return arr[row];
    }else if (component == 1){
        return arr1[row];
    }
    return @"测试";
}
- (void)myPickerView:(nonnull MyPickerView *)myPickerView titleForDidSelectRow:(NSInteger)row forComponent:(NSInteger)component{
    NSString * str = arr[0];
    NSString * str1 = arr[0];
    if (component == 0) {
        str = arr[row];
    }
    if (component == 1) {
        str1 = arr1[row];
    }
    
}

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
//}


-(void)addView2{
    float kuan = WindowWidth*0.8;
    bkview1 = [UIView new];
    bkview1.frame = CGRectMake(0, 0,WindowWidth , WindowHeight);
    bkview1.backgroundColor = kLightGrayColor;
    //bkview1.alpha = 0.99;
    [self.view addSubview:bkview1];
    
    bkview1.hidden = YES;
    
    UIView *view1 = [UIView new];
    view1.frame = CGRectMake((WindowWidth-kuan)/2, (WindowHeight-375)/2,kuan , 375);
    view1.backgroundColor = [UIColor whiteColor];
    view1.layer.cornerRadius = 10;
    view1.layer.masksToBounds = YES;
    [bkview1 addSubview:view1];
    
    UIImageView *bgImageView = [ReduceCode creatImageVeiwWithFrame:CGRectMake(0, 0, kuan, 225) imageName:@"bg" isCorner:NO];
    [view1 addSubview:bgImageView];
    
    UILabel *lab1 = [ReduceCode creatLabelWithFrame:CGRectMake(0, kMaxY(bgImageView.frame)+23, kuan/2, 20) title:@"20天燃脂跑" titleColor:UIColorFromRGB(0xe85f2b) font:18 textAlignment:NSTextAlignmentRight];
    [view1 addSubview:lab1];
    
    UILabel *lab2 = [ReduceCode creatLabelWithFrame:CGRectMake(kuan/2, kMaxY(bgImageView.frame)+23, kuan/2, 20) title:@"已经预约成功" titleColor:UIColorFromRGB(0x333333) font:18 textAlignment:NSTextAlignmentLeft];
    [view1 addSubview:lab2];
    
    UILabel *lab3 = [ReduceCode creatLabelWithFrame:CGRectMake(0, kMaxY(lab1.frame)+16, kuan, 20) title:@"链接设备即可体验" titleColor:UIColorFromRGB(0x333333) font:18 textAlignment:NSTextAlignmentCenter];
    //lab3.centerX = view1.centerX;
    [view1 addSubview:lab3];
    
    UIButton *but = [UIButton creatBtnWithFrame:CGRectMake(10, kMaxY(bgImageView.frame)+95, kuan-20, 45) btnTitle:@"知道了" btnTitleColor:kWhiteColor btnTitleFont:20 btnTagPrice:0 btnSetImage:nil btnBackgroundColor:UIColorFromRGB(0x47495f) isCorner:NO action:^(UIButton *button) {
        bkview1.hidden = YES;
    }];
    [view1 addSubview:but];
    but.layer.cornerRadius = 5;
    but.layer.masksToBounds = YES;
//    UIButton *cancelbtn1 = [[UIButton alloc] initWithFrame:CGRectMake(kMaxX(view1.frame)-17, (WindowHeight-375)/2-15.5, 31, 31)];
//    
//    [cancelbtn1 addTarget:self action:@selector(yincang) forControlEvents:UIControlEventTouchUpInside];
//    cancelbtn1.titleLabel.font = FONT(13);
//    cancelbtn1.layer.cornerRadius = 15.5;
//    cancelbtn1.layer.masksToBounds = YES;
//    [cancelbtn1 setBackgroundImage:[UIImage imageNamed:@"close"] forState:0];
//    [bkview1 addSubview:cancelbtn1];
//    
//    UIView *view2 = [UIView new];
//    view2.frame = CGRectMake(0, 0,kuan , 250);
//    view2.backgroundColor = UIColorFromRGB(0x313433);
//    [view1 addSubview:view2];
//    
//    UILabel *lab1 = [UILabel new];
//    lab1.frame = CGRectMake(0, kMaxY(view2.frame)+20, kuan, 17);
//    lab1.text = @"20天强力燃脂跑";
//    lab1.font = FONT(17);
//    lab1.textColor = UIColorFromRGB(0x333333);
//    lab1.textAlignment = 1;
//    [view1 addSubview:lab1];
//    
//    UILabel *lab2 = [UILabel new];
//    lab2.frame = CGRectMake(0, kMaxY(lab1.frame)+16, kuan, 17);
//    lab2.text = @"您已预约成功";
//    lab2.font = FONT(17);
//    lab2.textColor = UIColorFromRGB(0x333333);
//    lab2.textAlignment = 1;
//    [view1 addSubview:lab2];
//    
//    UILabel *lab3 = [UILabel new];
//    lab3.frame = CGRectMake(0, kMaxY(lab2.frame)+16, kuan, 17);
//    lab3.text = @"链接设备即可体验";
//    lab3.font = FONT(17);
//    lab3.textColor = UIColorFromRGB(0x333333);
//    lab3.textAlignment = 1;
//    [view1 addSubview:lab3];
    
}
-(void)xianshi{
    bkview1.hidden = NO;
}
-(void)yincang{
    bkview1.hidden = YES;
}
@end
